clear all; clc; close all; format short
addpath('auxiliar'); addpath('Simulated_Datasets')




%Vector of Parameters
load seed
rng(s);

%params_reentry_gbstanding
paramsSP
load initSP
SP;
Post_SP
Implied_Tax
Expected_policiesSP
simulation_SP
save Simulated_Datasets\SP_SIMULATION

%save Simulated_DatasetsSP_SIMULATION_20k

%% POST ESTIMATIOn
clear all;  addpath('auxiliar'); addpath('Simulated_Datasets');load SP_SIMULATION_20k
Welfare_cal %Computes Welfare gains. Requiers simDE from Baseline Model
ResultsSP

%% Saves used in other routines
clear all;  addpath('auxiliar'); addpath('Simulated_Datasets');load SP_SIMULATION_20k
welfare_saveSP % Saved to compute models in Extensions
save Simulated_Datasets\simSP
%%
clear all ; addpath('auxiliar'); addpath('Simulated_Datasets'); load SP_SIMULATION_20k
Transitions_save_SP
save Simulated_Datasets\Policies_for_TransitionSP

%% Quantitagtive Exercises
% Excercise I: Particle Filter, 3 Endogenous States, Centered
clear all;   addpath('auxiliar'); addpath('Simulated_Datasets');
load SP_SIMULATION_20k.mat

%Equilibruim_PoliciesSP
%Particle Filter Excercise. Requieres Particle_endoPublic from the Baselins
Particle_ENDO
save Simulated_Datasets\ParticleSPDE_ENDO

%% EVENT ANALSYS
clear all;  addpath('auxiliar'); addpath('Simulated_Datasets'); load SP_SIMULATION_20k.mat
Def_funcSP=Def_func;
clearvars -except Def_funcSP
load  SIMULATION_ERGODIC_DE
simul_experimentsDE
clearvars -except PubDebt_to_GDP_DE PvDebt_to_GDP_DE BGSIM_Defaulted_DE meanYDE bSIM_Defaulted_DE bSIM_Defaultedm1_DE bSIM_Defaultedm2_DE bSIM_Defaultedm3_DE bSIM_Defaultedm4_DE bSIM_Defaultedm5_DE BGSIM_Defaultedm1_DE BGSIM_Defaultedm2_DE BGSIM_Defaultedm3_DE BGSIM_Defaultedm4_DE BGSIM_Defaultedm5_DE BGSSm3_DE BGSSm2_DE BGSSm1_DE BGSS_DE BGSSp3_DE BGSSp2_DE BGSSp1_DE  bSSm3_DE bSSm2_DE bSSm1_DE bSS_DE bSSp3_DE bSSp2_DE bSSp1_DE SS_DE_th Def_funcDE
load SP_SIMULATION_20k
simul_experimentsSP
save Simulated_Datasets\events


%% PLOTS IN ORDER
Figures_1to3
Figure_4
Figure_5
Figure_6
Figure_7
Figure_8
Figure_9
Figure_10
Figure_11

%% Tables IN ORDER
Table_1
Table_2
Table_3
Table_4
Table_5